﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace ProceduralGolf
{
    public class LoadingScreen
    {
        SpriteBatch spriteBatch;
        SpriteFont font;

        public float Progress { get; set; }
        public String Message { get; set; }

        GraphicsDevice graphicsDevice;

        static IDictionary<Game, LoadingScreen> screens = new Dictionary<Game, LoadingScreen>();

        public static LoadingScreen GetLoadingScreen(Game game)
        {
            if (!screens.ContainsKey(game))
                screens[game] = new LoadingScreen(game);
            return screens[game];
        }

        private LoadingScreen(Game game)
        {
            graphicsDevice = game.GraphicsDevice;
            spriteBatch = new SpriteBatch(graphicsDevice);
            font = game.Content.Load<SpriteFont>("MyFont");
        }

        public void Draw()
        {
            String str = String.Format("{0}", Message);
            Vector2 position = new Vector2(graphicsDevice.Viewport.Width/2, graphicsDevice.Viewport.Height/2) - font.MeasureString(str)/2;
            graphicsDevice.Clear(Color.Gray);
            spriteBatch.Begin();
            spriteBatch.DrawString(font, str, position, Color.Black);
            spriteBatch.End();
        }
    }
}
